home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / srefv112.zip / POSTFILT.80 < prev    next >
Text File  |  1996-05-17  |  11KB  |  321 lines

  1. /* a sample of a SRE-FILTER "post-filter"
  2. This will mail a message to selected users, depending on the value
  3. of the request string, or the client's IP address.
  4. For general notes on how  POSTFILT is called, see the bottom of this file.
  5.  
  6. Note: if you modify this, you may wish to rename it to some other name
  7. (say, POSTF1.80); and change the POSTFILTER_NAME variable (in INITFILT.80)
  8. by hand (say, POSTFILTER_NAME="POSTF1")
  9. */
  10.   
  11. /*
  12.     ----------------------- A Mail Notification Facility ----------------
  13.  
  14. This will automatically send "e-mail alerts" to specified recipients given specified events.
  15. It calls the SREF_MAILIT procedure.
  16.  
  17. It requires that a valid SMTP Gateway be available (the SMTP Gateway
  18. is set by running SRE-FILTER's configurator and modifying the SMTP_GATEWAY variable)
  19. Note that if you may be able to use OS/2's SENDMAIL program to use the server as
  20. an SMTP gateway (see the TCP/IP command reference documentation).
  21.  
  22. To use this routine, you will need to set up an "event" list.  The event list
  23. should contain the following information:
  24.  a)   What type of event to examine (client or request string)
  25.  b)   The value that triggers a "match" (i.e.; a client's address, or a request for a particular file)
  26.  c)   The list of e-mail addresses to send "e-mail alerts" to
  27.  d)   An optional message to include in these alerts.
  28.  e)   An optional subject line
  29.  
  30. This routine uses the EVENTS.field.n  stem variable to store this event list.
  31.  
  32.   field should take one of 4 values
  33.      a)TYPE   : Either CLIENT or REQUEST (REQUEST is the "request string")
  34.      b)VALUE : A numeric IP address, or a target request string.  Either may contain * characters;
  35.               (either as domain wildcards or to signal "abbreviation matches")
  36.      c)RECIPIENTS: A space delimited list of e-mail  addresses
  37.      d)MESSAGE : An optional message.  It may contain CRLFs, and be quite long.
  38.      e)SUBJECT: An optional 1 line message to use as the SUBJECT.
  39.  
  40.    n is an integer value (that should run from 1.. "# of events")
  41.  
  42. You also must set EVENTS.0 equal to the "# of  events"
  43.  
  44. The algorithim works by:
  45.   From m=1.. to EVENTS.0
  46.       If EVENTS.TYPE.m=CLIENT, then see if client's numeric IP address
  47.           matches EVENTS.VALUE.m (with * acceptable as a wildcard)
  48.       If EVENTS.TYPE.m=REQUEST, see if the client's request string matches EVENTS.VALUE.m,
  49.           (with * signalling that abbreviation matching should be used).
  50.           NOTE: The SEL variable contains the original request string, before modifications
  51.                 by SRE-FILTER.  The match is against the entire request string,
  52.                 not just the Action!  Thus, a SEL of FOO.HTM?this_one
  53.                 will NOT match a target of FOO.HTM (but will match FOO.HTM*)
  54.                 In comparision, exact matches (say,
  55.                 in the access_file) compare the action to the target -- so
  56.                 any ?xxx is ignored.
  57.  
  58.  
  59.   If either occurs
  60.       Create a note containing time,date, server name, client's name, SRE-FILTER status
  61.       message, and  EVENTS.MESSAGE.m
  62.            Note that EVENTS.MESSAGE.m is optional.
  63.       If EVENTS.SUBJECT.j is missing, a generic subject line is used.
  64.       Sent this note to each e-mail addresss listed in EVENT.RECIPIENTS.m
  65.  
  66. If there is not SMTP_GATEWAY specified, or EVENTS.0=0, then a short
  67. synopsis of the request is displayed using SAY
  68.  
  69. Note that there may be multiple matches; so that several different e-mail alerts (to
  70. different sets of e-mail addresses, some of which may contain common 
  71. addresses) may be generated by each call to this routine.
  72.  
  73. Example:
  74.  
  75. EVENTS.0=3
  76.  
  77. EVENTS.TYPE.1="CLIENT"
  78. EVENTS.VALUE.1="*.*.*.*"
  79. EVENTS.RECIPIENTS.1="bob@hisorg.net  jill@staff.agency.gov "
  80.      Note that EVENTS.MESSAGE.1 is not set
  81.  
  82. EVENTS.TYPE.2="REQUEST"
  83. EVENTS.VALUE.2="PROJECTS/PROJ1.HTM"
  84. EVENTS.RECIPIENTS.2="ANDREW@myorg.org"
  85. EVENTS.MESSAGE.2="A request for PROJ1 was recieved "
  86. events.subject.2=' PROJ1 Request '
  87.  
  88. EVENTS.TYPE.3="REQUEST"
  89. EVENTS.VALUE.2="\PUT_FILE*"
  90. EVENTS.RECIPIENTS.3="WEBMASTER@MYORG.ORG"
  91. EVENTS.MESSAGE.3="A file upload has been recieved! "||crlf||" You may want to check it?"
  92.   Note the use of CRLF to add a line feed to the message.
  93.  
  94. Note when EVENTS.TYPE.m=REQUEST:
  95.   all / are converted to \ (in both the SEL and EVENTS.VALUE.n), and
  96.   leading and trailing \ are stripped
  97.  
  98.             --------------------------------------------------
  99. */
  100.  
  101. postfilt:
  102.  
  103. CRLF = '0d0a'x
  104.  
  105. /*  ==============  INSERT  EVENTS list here   ================  */
  106.  
  107. events.0=0
  108.  
  109.  
  110.  
  111. /* ============ DO NOT CHANGE BELOW HERE  ===================== */
  112.  
  113. parse arg amessage,source,request,sel,tempfile,gateway
  114. parse var source serveraddr serverport transaction_number clientaddr clientport
  115.  
  116.  
  117. if gateway=0 then do                    /* if no gateway specified, do nothing */
  118.   call say_stuff
  119.   return ' '
  120. end
  121. if events.0=0 then do
  122.   call say_stuff
  123.   return ' '
  124. end
  125.  
  126.  
  127. sname=servername()                       /* info used below */
  128. cname=clientname()
  129. atime=time()
  130. adate=date()
  131. CRLF = '0d0a'x
  132.  
  133.  
  134. /* loop through events list .. */
  135. didit=0
  136. do jj=1 to events.0
  137.     ok=0
  138.     if events.TYPE.jj="CLIENT" then
  139.        ok=goodip(events.VALUE.jj,clientaddr)
  140.     else 
  141.       if events.type.jj='REQUEST' then do
  142.          ok=goodsel(events.value.jj,sel)
  143.      end
  144.     if ok=0 then iterate
  145.  
  146.     if didit=0 then
  147.        say " Using gateway at " gateway
  148.     didit=1
  149.  
  150.  
  151. /* if here, a match occurred */
  152.    address_list=events.recipients.jj
  153.  
  154.    if symbol('events.subject.jj')='VAR' then  
  155.           asubject='Subject: '||events.subject.jj
  156.    else
  157.           asubject='Subject: Notification of WEB transaction  '
  158.  
  159.    themessage="Date: " || adate || ' ' ||atime
  160.    themessage=themessage||crlf||'From: WebServer@'||sname
  161.    themessage=themessage||crlf||asubject
  162.    themessage=themessage||crlf||'To: '||address_list||crlf
  163.  
  164.    themessage=themessage||crlf||'An e-mail alert from the Web Server at '||sname
  165.    themessage=themessage||crlf||"    Date of occurrence: " || adate || ' ' ||atime
  166.    themessage=themessage||crlf||'     Request by client: '|| cname
  167.    themessage=themessage||crlf||'        Request string: '|| sel
  168.    themessage=themessage||crlf||' Server status message: '|| amessage
  169.  
  170.    if symbol('events.message.jj')='VAR' then  /* check for a mess up */
  171.       themessage=themessage||crlf||"Notes:"||crlf||events.message.jj||crlf
  172.    else
  173.       themessage=themessage||crlf
  174.  
  175.    foo=sref_mailit(address_list,themessage, gateway)
  176.    say  " Event " jj ", MAILIT status: "foo
  177.  
  178. end                     /* try next event */
  179.  
  180. return ' '
  181.  
  182. /* -----------------------------------------------------------------------*/
  183. /* see if match (or abbreviation match) the sel                          */
  184. /* -----------------------------------------------------------------------*/
  185. goodsel: procedure
  186. parse  arg asel,thesel
  187. asel=translate(asel) ; thesel=translate(thesel)
  188. asel=translate(asel,'\','/') ; asel=strip(asel,,'\')
  189. thesel=translate(thesel,'\','/') ; thesel=strip(thesel,,'\')
  190.  
  191. if asel=thesel then return 1   /* exact match */
  192. /* do abbreviation match? */
  193. if right(asel,1)<>'*' then return 0   /* nope */
  194.  
  195. asel=left(asel,length(asel)-1)  /* try an abbreviation match */
  196. return abbrev(thesel,asel)
  197.  
  198.  
  199. /* -----------------------------------------------------------------------*/
  200. /* see if matches one of a set of good ips (1 if yes)*/
  201. /* -----------------------------------------------------------------------*/
  202. goodip: procedure 
  203.  
  204. parse arg anips,cip0
  205. parse var anips ip.1 '.' ip.2 '.' ip.3 '.' ip.4
  206. parse var cip0 cip.1 '.' cip.2 '.' cip.3 '.' cip.4
  207. match=1
  208. do mm2=1 to 4
  209.       if ip.mm2="*" then iterate
  210.       if ip.mm2=cip.mm2 then iterate
  211.       match=0       /*if here, not a match */
  212.       leave
  213. end
  214. return match
  215.  
  216.  
  217. /* A simple transaction recorder (used if no SMTP_GATEWAY specified */
  218. say_stuff:
  219. say "  - - - - - "
  220. say time() ' ' date()
  221. say  "  Message= "  amessage
  222. say  " Source=  " source
  223. say   " Request= "  request
  224. say  " Sel = "  sel
  225. return 
  226.  
  227.  
  228.  
  229. /*******************************************************************
  230.  *******************************************************************
  231.   *******************************************************************/
  232.  
  233. /*
  234.          ---------------- General notes  ------------------------
  235.  
  236. SRE-FILTER  call this procedure when the POST_FILTER variable is set to YES.
  237.  
  238. 6 arguments are passed here:
  239.     amessage
  240.     source
  241.     request
  242.     sel0
  243.     tempfile
  244.     params
  245.  
  246. Amessage 
  247.     is generated by SRE-FILTER, and indicates what SRE-FILTER did with this request.
  248.  
  249. Source,request,and sel0 are generated by GoServe, and contain:
  250.  
  251.   Source 
  252.        serveraddr serverport transaction_number clientaddr clientport
  253.   Request
  254.     verb uri protocol 
  255.   Sel0
  256.     action '?' awords  (?awords may not be present
  257.  
  258. Tempfile is set in SRE-FILTER
  259.   Tempfile
  260.     A temporary file name. It may have been used to construct the response, so you probably should
  261.     delete it first (use SYSFILEDELETE(TEMPFILE) ).
  262.  
  263. Params
  264.    Are optional parameters sent by SRE-FILTER.  Currently, it contains the name of the
  265.    SMTP gateway (set in the SMTP_GATEWAY variable of SRE-FILTER).
  266.  
  267. Example:
  268.      message               HTML File sent:/INDEX.HTM
  269.      Source                151.121.65.143 80 3 219.134.78.12 1026
  270.      request                GET /sampask2.htm HTTP/1.0
  271.      sel0                   sampask2.htm
  272.      tempfile               D:/GOHTTP/$10.80
  273.      params                mail.myprovider.net
  274.  
  275.  
  276. Note on Amessage:
  277.   The folllowing lists the "messages" that SRE-FILTER may send.  Note that the ||varname
  278.   means the value of Varname is appended to the message.  Also note that when varname=SEL,
  279.   the SEL may be different then SEL0 (say, if a ~ replacement occurred).
  280.  
  281.     Pre-filter used
  282.     Cached file sent: ||sel0
  283.     Bad HTTP Protocol
  284.     Unauthorized access
  285.     No client name found, access denied
  286.     Logon denied to non-inhouse user
  287.     Pre-filter used
  288.     Alias invoked permanent redirect
  289.     Alias invoked temporary redirect
  290.     Transfered non-data directory file
  291.     Access to file denied:  ||sel
  292.     Ping request
  293.     CONTROL Statistics request
  294.     Host request
  295.     Control Moveaudit
  296.     Control Reset all
  297.     Variable display
  298.     !Special request denied: ||sel
  299.     Message box access
  300.     Message box access denied
  301.     Message box viewing
  302.     Special request processing unknown:||sel
  303.     HEAD request: Document not found:  ||sel0
  304.     Head request
  305.     Document not found
  306.     Server is busy
  307.     Non-HTML File sent:||file
  308.     HTML File sent:||file
  309.     HTML File sent (with ssi):||file
  310.     Mappable image request:'||foo
  311.     GET request:||action
  312.     Server busy
  313.     POST error: too much data
  314.     POST error: could not read data
  315.     POST request:||sel
  316.     POST problem:||sel
  317.     CGI-BIN access||sel
  318.  
  319. **************************************************************************/
  320.  
  321.